Skip to content

Use application-scoped StorageCredentialCache #2022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

XN137
Copy link
Contributor

@XN137 XN137 commented Jul 10, 2025

since StorageCredentialCache is application scoped and after 6ddd148 its constructor no longer uses the RealmContext passed into getOrCreateStorageCredentialCache we can now let all PolarisEntityManager instances share the same StorageCredentialCache.

@github-project-automation github-project-automation bot moved this to PRs In Progress in Basic Kanban Board Jul 10, 2025
@XN137 XN137 marked this pull request as ready for review July 10, 2025 08:09
@snazy snazy marked this pull request as draft July 10, 2025 08:17
@snazy
Copy link
Member

snazy commented Jul 10, 2025

Converted to "draft state", as it depends on another PR

Copy link
Member

@snazy snazy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a ton for this!

dimas-b
dimas-b previously approved these changes Jul 10, 2025
Copy link
Contributor

@dimas-b dimas-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring for application-scoped data. From my POV, this PR improves control over Polaris heap usage by consolidating cached credentials in one cache object as opposed to having a (virtually unbounded) collection of caches.

public StorageCredentialCache(
RealmContext realmContext, PolarisConfigurationStore configurationStore) {
this.realmContext = realmContext;
public StorageCredentialCache(PolarisConfigurationStore configurationStore) {
this.configurationStore = configurationStore;
cache =
Caffeine.newBuilder()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind making the max cache size (by entries) configurable? Now that the caches is shared across realms, configuring its side is more important to users, I guess.

I suppose the cache size has to be a global configuration (maybe a constructor parameter injected via CDI producers + Quarkus config).

Copy link
Contributor Author

@XN137 XN137 Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've added a commit for this, is this what you had in mind?
please double check the naming, module and package.

also imo this raises some questions:

a) how should the new cache config relate to FeatureConfiguration.STORAGE_CREDENTIAL_CACHE_DURATION_SECONDS and FeatureConfiguration.STORAGE_CREDENTIAL_DURATION_SECONDS ?

b) what to do with the InMemoryEntityCache which seems to deal with a single realm? (and thus its max size cant be configured at the application level)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InMemoryEntityCache

I was thinking about that one, too. And I suspect it should be refactored in a similar way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InMemoryEntityCache -> +1 to similar refactoring (better control over heap usage)

@github-project-automation github-project-automation bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Jul 10, 2025
@XN137 XN137 force-pushed the application-scoped-StorageCredentialCache branch 2 times, most recently from 7f1eaf4 to bf5a42e Compare July 11, 2025 07:56
@XN137
Copy link
Contributor Author

XN137 commented Jul 11, 2025

rebased after 19f44d8 due to conflicts

@XN137 XN137 force-pushed the application-scoped-StorageCredentialCache branch from bf5a42e to 23c1d4e Compare July 14, 2025 10:43
@XN137 XN137 force-pushed the application-scoped-StorageCredentialCache branch from 23c1d4e to db1c4c5 Compare July 14, 2025 11:18
@XN137
Copy link
Contributor Author

XN137 commented Jul 14, 2025

rebased after multiple conflicts, should be ready for review now

@XN137 XN137 marked this pull request as ready for review July 14, 2025 11:35
public StorageCredentialCache(
RealmContext realmContext, PolarisConfigurationStore configurationStore) {
this.realmContext = realmContext;
public StorageCredentialCache(PolarisConfigurationStore configurationStore) {
this.configurationStore = configurationStore;
cache =
Caffeine.newBuilder()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InMemoryEntityCache

I was thinking about that one, too. And I suspect it should be refactored in a similar way.

public interface QuarkusStorageCredentialCacheConfig extends StorageCredentialCacheConfig {
@WithName("max-entry-count")
@WithDefault("10000")
@Min(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cache =
Caffeine.newBuilder()
.maximumSize(CACHE_MAX_NUMBER_OF_ENTRIES)
.maximumSize(cacheConfig.maxEntryCount())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR, but related to Nessie's persistence cache, discussing with Ben Manes, we opted to add those as well:

            .executor(Runnable::run)
            .scheduler(Scheduler.systemScheduler())

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not in this PR, but mentioning for posterity.

Copy link
Contributor

@dimas-b dimas-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 Thanks, @XN137 !

As the next step, I suppose it might be worth introducing a request-scoped facade to the credentials cache similar to RealmConfig.


@ConfigMapping(prefix = "polaris.storage-credential-cache")
public interface QuarkusStorageCredentialCacheConfig extends StorageCredentialCacheConfig {
@WithName("max-entry-count")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: max-entries-count?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, just max-entries - it's a count, no need to repeat that ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max-entries LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants